import os
import sys
import ntpath
print(os.path)
path=os.path.dirname(__file__)#获取当前路径，绝对路径
print(path)

# #用with结构代替close
# with open(r'C:\Users\hp\Desktop\aa.txt','rb') as stream:
#     c=stream.read()
#
#     path = os.path.dirname(__file__)  # 获取当前路径，绝对路径
#     path1=os.path.join(path,'bb.txt')
#     with open(path1,'wb') as wstream:
#         wstream.write(c)
# print('复制完成')

#绝对路径找文件
from posixpath import isabs
r=os.path.isabs(r'C:\Users\hp\Desktop\aa.txt')
print('********',r)

#相对路径
path=os.path.dirname(__file__)
print(path)
r=os.path.isabs(r'project1/bb.txt')
print('*******',r)

#通过相对路径得到绝对路径
path=os.path.abspath('bb.text')
print('****',path)

path=os.getcwd()#等同于os.path.dirname(__file__)

#得到文件路径和名字
r=r'C:\Users\hp\Desktop\aa.txt'
result=os.path.split(r)
print('***',result)

#提取扩展名
result=os.path.splitext(r)
print('*****',result)

#文件大小字节
size=os.path.getsize(path)
print(size)